#include "CObject.h"

CObject::CObject()
{
	m_Xpos			= 0;
	m_Ypos			= 0;
	m_fDeep			= 0.0f;
	m_nWidth		= 0;
	m_nHeight		= 0;
	m_PrevXpos		= m_Xpos;
	m_PrevYpos		= m_Ypos;
	m_isAlive		= true;
	m_isVisible		= true;
	m_isColliable	= true;

	m_pImage		= new CTexture();
}

CObject::CObject(float Xpos , float Ypos , float deep , int width , int height)
{
	m_Xpos			= Xpos;
	m_Ypos			= Ypos;
	m_fDeep			= deep;
	m_nWidth		= width;
	m_nHeight		= height;
	m_PrevXpos		= Xpos;
	m_PrevYpos		= Ypos;
	m_isAlive		= true;
	m_isVisible		= true;
	m_isColliable	= true;

	m_pImage		= new CTexture();
}

CObject::~CObject()
{
	
}

//
//	Set methods
//


//--------------------------------------//
// Name : SetImage                      //
// Desc : Set the image for this sprite //
//--------------------------------------//
void CObject::SetImage(CTexture *Image)
{
	if(Image == NULL)
		return;

	m_pImage = Image;
}



//-----------------------------------------//
// Name : SetPosition                      //
// Desc : Set new position for this object //
//-----------------------------------------//
void CObject::SetPosition(float NewXpos , float NewYpos)
{
	m_Xpos		= NewXpos;
	m_Ypos		= NewYpos;
}


//-------------------------------------------//
// Name : SetXpos							 //
// Desc : Set new X position for this object //
//-------------------------------------------//
void CObject::SetXpos(float NewXpos)
{
	m_Xpos		= NewXpos;
}



//-------------------------------------------//
// Name : SetYpos							 //
// Desc : Set new Y position for this object //
//-------------------------------------------//
void CObject::SetYpos(float NewYpos)
{
	m_Ypos		= NewYpos;
}


//--------------------------------------------------------//
// Name : SetSize										  //
// Desc : Set new size (new width , new height) for this  //
//			object										  //
//--------------------------------------------------------//
void CObject::SetSize(int NewWidth , int NewHeight)
{
	m_nWidth	= NewWidth;
	m_nHeight	= NewHeight;
}


//--------------------------------------------------------//
// Name : SetWidth										  //
// Desc : Set new size of width for this object			  //
//--------------------------------------------------------//
void CObject::SetWidth(int NewWidth)
{
	m_nWidth	= NewWidth;
}


//--------------------------------------------------------//
// Name : SetHeight										  //
// Desc : Set new size of height for this object		  //
//--------------------------------------------------------//
void CObject::SetHeight(int NewHeight )
{
	m_nHeight	= NewHeight;
}







//---------------------------------------------------//
// Name : SetPrevPosition							 //
// Desc : Store the previous position of this object //
//			for use when needed						 //
//---------------------------------------------------//
void CObject::SetPrevPosition(float NewPrevXpos , float NewPrevYpos)
{
	m_PrevXpos = NewPrevXpos;
	m_PrevYpos = NewPrevYpos;
}



//-----------------------------------------------------//
// Name : SetPrevXpos								   //
// Desc : Store the previous X position of this object //
//			for use when needed						   //
//-----------------------------------------------------//
void CObject::SetPrevXpos(float Xpos)
{
	m_PrevXpos = Xpos;
}


//-----------------------------------------------------//
// Name : SetPrevYpos								   //
// Desc : Store the previous Y position of this object //
//			for use when needed						   //
//-----------------------------------------------------//
void CObject::SetPrevYpos( float Ypos)
{
	m_PrevYpos = Ypos;
}


//---------------------------------//
// Name : SetAlive		           //
// Desc : Set object alive or dead //
//---------------------------------//
void CObject::SetAlive(bool isAlive /*= true*/)
{
	m_isAlive = isAlive;
}


//----------------------------------------//
// Name : SetVisible                      //
// Desc : Set object Visible or invisible //
//----------------------------------------//
void CObject::SetVisible(bool isVisible /*= true*/)
{
	m_isVisible = isVisible;
}


//--------------------------------------------------------//
// Name : SetColliable                                    //
// Desc : Set type of object , colliable or non-colliable //
//--------------------------------------------------------//
void CObject::SetColliable(bool isColliable /*= true*/)
{
	m_isColliable = isColliable;
}



//-------------------------------------------------------------------------------//
// Name : SetDeep																 //
// Desc : Set the deep of this object											 //
//			Deep range : 0.0f( closest to screen ) - 1.0f ( farthest to screen ) //
//-------------------------------------------------------------------------------//
void CObject::SetDeep(float deep)
{
	m_fDeep = deep;
}




//
//	Get methods
//


//-------------------------------------------------------//
// Name : GetXposition                                   //
// Desc : Get the current X-axis position of this object //
//-------------------------------------------------------//
float CObject::GetXposition( )
{
	return m_Xpos;
}

//-------------------------------------------------------//
// Name : GetYposition                                   //
// Desc : Get the current Y-axis position of this object //
//-------------------------------------------------------//
float CObject::GetYposition( )
{
	return m_Ypos;
}


//--------------------------------------------------------//
// Name : GetPrevXposition                                //
// Desc : Get the previous X-axis position of this object //
//--------------------------------------------------------//
float CObject::GetPrevXposition( )
{
	return m_PrevXpos;
}


//--------------------------------------------------------//
// Name : GetPrevYposition                                //
// Desc : Get the previous Y-axis position of this object //
//--------------------------------------------------------//
float CObject::GetPrevYposition( )
{
	return m_PrevYpos;
}






//------------------------------------//
// Name : GetDeep                     //
// Desc : Get the deep of this object //
//------------------------------------//
float CObject::GetDeep()
{
	return m_fDeep;
}




//---------------------------------//
// Name : GetWidth                 //
// Desc : Get width of this object //
//---------------------------------//
int	CObject::GetWidth( )
{
	return m_nWidth;
}


//----------------------------------//
// Name : GetHeight                 //
// Desc : Get height of this object //
//----------------------------------//
int	CObject::GetHeight( )
{
	return m_nHeight;
}



//--------------------------------------------//
// Name : GetBoundBox                         //
// Desc : Get the bounding box of this object //
//--------------------------------------------//
RECT CObject::GetBoundBox()
{
	RECT r;

	r.left		= m_Xpos;
	r.right		= r.left + m_nWidth ;
	r.top		= m_Ypos;
	r.bottom	= r.top + m_nHeight;

	return r;
}


//-----------------------------------------//
// Name : IsAlive                          //
// Desc : This object still alive or not ? //
//-----------------------------------------//
bool CObject::IsAlive()
{
	return m_isAlive;
}


//----------------------------------------//
// Name : IsVisible                       //
// Desc : This object is visible or not ? //
//----------------------------------------//
bool CObject::IsVisible()
{
	return m_isVisible;
}


//------------------------------------------//
// Name : IsColliable                       //
// Desc : This object is colliable or not ? //
//------------------------------------------//
bool CObject::IsColliable()
{
	return m_isColliable;
}

//----------------------------------------------//
// Name : IsCollision                           //
// Desc : Collision detection with other object //
//----------------------------------------------//
bool CObject::IsCollision(CObject* pObject)
{
	RECT r1 = GetBoundBox();
	RECT r2	= pObject->GetBoundBox();

	if ( r1.top < r2.bottom && r1.bottom > r2.top 
		&& r1.left < r2.right && r1.right > r2.left )
		return true;

	return false;
}



//-------------------------------------------//
// Name : Move                               //
// Desc : Move an object by X and Y distance //
//-------------------------------------------//
void CObject::Move(float dX , float dY)
{
	m_Xpos += dX;
	m_Ypos += dY;
}





//-----------------------------------//
// Name : Update					 //
// Desc : Using to update this objec //
//-----------------------------------//
void CObject::Update(float deltalTime)
{

}


//------------------------------------------------//
// Name : Render								  //
// Desc : Using to render this object into screen //
//------------------------------------------------//
void CObject::Render( float camPosX /*= 0*/ , float camPosY /*= 0 */ )
{
	RECT scrRect;

	scrRect.left	= 0;
	scrRect.right	= scrRect.left + m_nWidth;
	scrRect.top		= 0;
	scrRect.bottom	= scrRect.top + m_nHeight;

	m_pImage->Draw( m_Xpos - camPosX , m_Ypos - camPosY , m_fDeep , &scrRect , D3DCOLOR_XRGB(255,255,255) );
}



